from info.module.passport import passport_bp
from flask import request,current_app,abort,make_response
from info.utiltis.captcha.captcha import captcha
from info import redis_store,constants


@passport_bp.route('/image_code')
def get_image_code():

    code_id = request.args.get('code_id')

    if not code_id:
        current_app.logger.error('参数不足')
        abort(403)

    image_name,image_code,image_data = captcha.generate_captcha()

    try:
        redis_store.setex('ImageCode_%s' % code_id,constants.IMAGE_CODE_REDIS_EXPIRES,image_code)
    except Exception as e:
        current_app.logger.error(e)
        abort(500)
    response = make_response(image_data)
    response.headers['Content-Type'] = 'image/JPEG'
    return response


@passport_bp.route('/sms_code',method = ['POST'])

def send_smscode():
    pass 